var jc = {
    convert_to_string: function (json) {
        //去除注释行
        for (var i = json.length - 1; i >= 0; i--) {
            var firstValue = json[i][0];
            //alert(firstValue);
            if (typeof (firstValue) == "string" && firstValue.indexOf("#") >= 0 && firstValue.indexOf('#%') < 0) {
                json.splice(i, 1);
            }
        }

        //转置
        var out_put = [];
        var key_row = json[0];
        for (var j = 1; j < json.length; j++) {
            var data = json[j];
            var json_item = {};
            for (var i = 0; i < key_row.length; i++) {
                var str = key_row[i];
                if (str.indexOf("[END]") >= 0)
                    break;

                var keymix = str.split(":");
                // alert(keymix);
                var key = keymix[0];
                key = key.replace("#%", '');
                var type = keymix[1];
                switch (type) {
                    case 's32':
                    case 's64':
                        {
                            json_item[key] = parseInt(data[i]);
                        }
                        break;
                    case 'float':
                        {
                            json_item[key] = parseFloat(data[i]);
                        }
                        break;
                    case 'bool':
                        switch (data[i]) {
                            case "true":
                                json_item[key] = true;
                                break;
                            case "false":
                                json_item[key] = false;
                                break;
                            default:
                                json_item[key] = false;
                                return 0;
                        }
                        break;
                    case 'json':
                        if (data[i] == "null") {
                            json_item[key] = null;
                        }
                        json_item[key] = JSON.parse(data[i]);
                        //alert(strs);
                        break;
                    case 'string':
                        json_item[key] = data[i];
                        break;
                    default:
                        alert(type);
                        return "{}";
                }
            }

            out_put.push(json_item);
        }

        return JSON.stringify(out_put);
    }
}

export default jc;